<template>
	<view ref='block' class='_block' :style='{width:width,height:height,"flex-shrink":this["flex-shrink"]}'>
		<slot></slot>
	</view>
</template>

<script>
	import Vue from 'vue'

	export default {
		name: "block",
		props: {
			length: {
				type: String,
				default: '100%'
			},
		
		},
		data: function() {
			return {
				height: '100%',
				width: '100%',
				'flex-shrink': 0,
				run: false,
				layoutConfig : {
					//加载布局之后再显示布局，否则可能会显示布局前的布局
					afterLoadedShow: true,
					//加载布局(Vue)前对应dom元素的样式(当afterLoadedShow为true时生效)
					registerCSS: `
						hiv{display:none;}
						viv{display:none;}
						rhiv{display:none;}
						rviv{display:none;}
						block{display:none;}
						pow{display:none;}
						wiv{display:none;}
						rwiv{display:none;}
					`,
					version: 'V1.11'
				},
				flexMapper : {
					"start": "flex-start",
					"end": "flex-end",
					"center": "center",
					"evenly": "space-evenly",
					"around": "space-around",
					"between": "space-between"
				}
			}
		},
		methods:{
			getOrDefault(mapper, value) {
				if (mapper[value] == null)
					return value;
				else return mapper[value];
			},
			getWrap(wrap, rwrap) {
				if (wrap)
					return 'wrap';
				else if (rwrap)
					return 'wrap-reverse';
				else 'nowrap';
			}
		},
		created: function() {
			if (parseInt(Vue.version[0]) == 1) {
				if (!this.$data.run) {
					this.$data.run = true;
					if (this.$parent.$el.className.indexOf('_viv') != -1 || this.$parent.$el
						.className.indexOf('_rviv') != -1) {
						this.$data.width = '0%';
						this.$data.height = this.length;
		
					} else if (this.$parent.$el.className.indexOf('_hiv') != -1 || this.$parent.$el
						.className.indexOf('_rhiv') != -1 || this.$parent.$el.className.indexOf(
							'_wiv') != -1 || this.$parent.$el.className.indexOf('_rwiv') != -1) {
		
						this.$data.height = '0%';
						this.$data.width = this.length;
		
					}
		
				}
			}
		},
		mounted: function() {
			if (parseInt(Vue.version[0]) > 1) {
				if (!this.$data.run) {
					this.$data.run = true;
					if (this.$parent.$el.className.indexOf('_viv') != -1 || this.$parent.$el
						.className.indexOf('_rviv') != -1) {
						this.$data.width = '0%';
						this.$data.height = this.length;
		
					} else if (this.$parent.$el.className.indexOf('_hiv') != -1 || this.$parent.$el
						.className.indexOf('_rhiv') != -1 || this.$parent.$el.className.indexOf(
							'_rwiv') != -1 || this.$parent.$el.className.indexOf('_wiv') != -1) {
		
						this.$data.height = '0%';
						this.$data.width = this.length;
					}
				}
			}
		}
	}
</script>

<style>

</style>
